package com.net.xpay.core.manager.impl;

import com.google.common.base.Preconditions;
import com.net.common.annotation.ReadTransactional;
import com.net.common.dao.BasicMapper;
import com.net.common.manager.AbstractVersionedManager;
import com.net.xpay.core.dao.UserAccountMapper;
import com.net.xpay.core.domain.UserAccount;
import com.net.xpay.core.manager.UserAccountManager;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;


@Component
@ReadTransactional
public class UserAccountManagerImpl extends AbstractVersionedManager<UserAccount> implements UserAccountManager{

    @Autowired
    private UserAccountMapper mapper;


    @Override
    protected BasicMapper<Long, UserAccount> getMapper() {
        return mapper;
    }

    @Override
    public UserAccount getByIdWithLock(Long id) {
        Preconditions.checkArgument(id != null);
        return mapper.getByIdWithLock(id);
    }

    @Override
    public List<UserAccount> findByIds(List<Long> ids) {
        Preconditions.checkArgument(CollectionUtils.isNotEmpty(ids));
        return nonEmptyList(mapper.findByIds(ids));
    }

    @Override
    public UserAccount findById(Long id) {
        return mapper.selectByPrimaryKey(id);
    }
}
